#pragma once

#include <stdint.h>
#include <stdbool.h>
/*
参考
https://www.runoob.com/tags/ref-canvas.html
*/

#ifdef __cplusplus
extern "C" {
#endif


#define CANVAS_LINE_STYLE_SOLID 0 // 实线
#define CANVAS_LINE_STYLE_DASH 1  // 虚线
#define CANVAS_LINE_STYLE_DOT 2   // 点线


#define CANVAS_FONT_STYLE_BOLD 1      // 加粗
#define CANVAS_FONT_STYLE_ITALIC 2    // 斜体
#define CANVAS_FONT_STYLE_UNDERLINE 4 // 下滑线
#define CANVAS_FONT_STYLE_STRIKEOUT 8 // 删除线

#define CANVAS_TEXT_ALIGN_LEFT 0   // 靠左
#define CANVAS_TEXT_ALIGN_RIGHT 1  // 靠右
#define CANVAS_TEXT_ALIGN_CENTER 2 // 居中

#define CANVAS_TEXT_BASELINE_TOP 0        // 靠上
#define CANVAS_TEXT_BASELINE_BOTTOM 1     // 靠下
#define CANVAS_TEXT_BASELINE_MIDDLE 2     // 居中
#define CANVAS_TEXT_BASELINE_ALPHABETIC 3 // 按字体基线


typedef struct _canvas* canvas_t;

typedef struct _canvas_image *canvas_image_t;

typedef struct _canvas_font *canvas_font_t;

typedef uint32_t canvas_color_t;

#define canvas_color_rgb(r,g,b) (r<<16|g<<8|b)

canvas_t canvas_create(void* native_window);
void canvas_destroy(canvas_t c);
void canvas_resize(canvas_t c, int w, int h);
void canvas_begin_draw(canvas_t c);
void canvas_end_draw(canvas_t c);
void canvas_clear(canvas_t c, canvas_color_t color);
void canvas_push_clip_rect(canvas_t c, int x, int y, int width, int height);
void canvas_pop_clip_rect(canvas_t c);

void canvas_set_fill_color(canvas_t c, canvas_color_t color);
void canvas_set_line_width(canvas_t c, int width);
void canvas_set_line_style(canvas_t c, int style);
void canvas_set_line_color(canvas_t c, canvas_color_t color);

//----------------------- 画框 ---------------------------
void canvas_fill_rect(canvas_t c, int x, int y, int width, int height);
void canvas_draw_rect(canvas_t c, int x, int y, int width, int height);
void canvas_fill_round_rect(canvas_t c, int x, int y, int width, int height, int radius);
void canvas_draw_round_rect(canvas_t c, int x, int y, int width, int height, int radius);
void canvas_fill_ellipse(canvas_t c, int x, int y, int rx, int ry);
void canvas_draw_ellipse(canvas_t c, int x, int y, int rx, int ry);


//----------------------- 画线 ---------------------------
/*
void canvas_begin_path(canvas_t c);
void canvas_close_path(canvas_t c);
void canvas_move_to(canvas_t c, int x, int y);
void canvas_line_to(canvas_t c, int x, int y);
void canvas_arc_to(canvas_t c, int x1, int y1, int x2, int y2, int radius);
void canvas_fill_path(canvas_t c);
void canvas_stroke_path(canvas_t c);
void canvas_draw_line(canvas_t c, int x1, int y1, int x2, int y2);
*/

//----------------------- 画图 ---------------------------
canvas_image_t canvas_create_image(canvas_t c, const void * bgra_pixel, int width, int height);
void canvas_image_get_size(canvas_image_t img, int* w, int* h);
void canvas_destroy_image(canvas_image_t img);
void canvas_draw_image(canvas_t c, canvas_image_t img, int x, int y, int w, int h);
void canvas_draw_image_part(canvas_t c, canvas_image_t img, int sx, int sy, int sw, int sh, int x, int y, int w, int h);


//----------------------- 画字 ---------------------------
canvas_font_t canvas_create_font(canvas_t c, const char *name, int font_size, int font_style);
void canvas_destroy_font(canvas_font_t font);
void canvas_set_font(canvas_t c, canvas_font_t font);
void canvas_set_text_align(canvas_t c, int text_align); 
void canvas_set_text_baseline(canvas_t c, int text_baseline); 
void canvas_draw_text(canvas_t c, const char *text, int textlen, int x, int y, int w, int h);
bool canvas_measure_text(canvas_t c, const char *text, int textlen, int *width, int *height);



#ifdef __cplusplus
}
#endif
